Add rest of shims to hook up Garmin/USB layers.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 16 Sep 2004 04:43:15 +0000 (04:43 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Thu, 16 Sep 2004 04:43:15 +0000 (04:43 +0000)
gpsbabel/jeeps/garminusb.h
gpsbabel/jeeps/gpsread.c
gpsbabel/jeeps/gpssend.c
gpsbabel/jeeps/gpsserial.c

index 2a063a95f3e3454f3586f8b3bff3004617ac4d8f..eb448b67fee995600a7ed1575fef3ee3c4bcd653 100644 (file)
@@ -38,7 +38,7 @@ union {
        unsigned char datasz[4];
        unsigned char databuf[1]; /* actually an variable length array... */
        } gusb_pkt;
-       unsigned char dbuf[MAX_GPS_PACKET_SIZE];
+       unsigned char dbuf[1024];
 } garmin_usb_packet;
 
 /*
index 6f9004eb3058be78e91fc023752fd5334ca315dd..d37fe6f3e4cbe5745c3f10f3a0e1d667a9e46f81 100644 (file)
@@ -82,6 +82,10 @@ int32 GPS_Packet_Read(int32 fd, GPS_PPacket *packet)
     len = 0;
     isDLE = gpsFalse;
     p = (*packet)->data;
+
+    if (gps_is_usb) {
+           return GPS_Packet_Read_usb(fd, packet);
+    }
     
     start = GPS_Time_Now();
     GPS_Diag("Rx Data:");
@@ -191,6 +195,10 @@ int32 GPS_Packet_Read(int32 fd, GPS_PPacket *packet)
 
 int32 GPS_Get_Ack(int32 fd, GPS_PPacket *tra, GPS_PPacket *rec)
 {
+    if (gps_is_usb) {
+           return 1;
+    }
+
     if(!GPS_Packet_Read(fd, rec))
        return 0;
 
@@ -208,33 +216,3 @@ int32 GPS_Get_Ack(int32 fd, GPS_PPacket *tra, GPS_PPacket *rec)
 
     return 1;
 }
-
-
-
-
-
-#if 0
-
-int32 ajb(int32 fd)
-{
-    UC     u;
-    int32  n;
-    
-    while(1)
-    {
-       if((n=GPS_Serial_Chars_Ready(fd)))
-       {
-           if(read(fd,&u,1)==-1)
-           {
-               perror("read");
-               GPS_Error("NMEA Read: Read error");
-               gps_errno = FRAMING_ERROR;
-               return 0;
-           }
-           printf("%d %c\n",u,u);
-       }
-    }
-
-    return 0;
-}
-#endif
index fce480cb25820b5a470d5bafd6b41c7bcbe793ef..c4b299d7a9ffe448f8ac19d0130bd205663e6c29 100644 (file)
@@ -45,9 +45,15 @@ void GPS_Make_Packet(GPS_PPacket *packet, UC type, UC *data, int16 n)
     
     int32 i;
     UC  chk=0;
+
     
     p = data;
     q = (*packet)->data;
+
+    if (gps_is_usb) {
+           GPS_Make_Packet_usb(packet, type, data, n);
+           return;
+    }
     
     (*packet)->dle   = DLE;
     (*packet)->edle  = DLE;
@@ -55,7 +61,7 @@ void GPS_Make_Packet(GPS_PPacket *packet, UC type, UC *data, int16 n)
     (*packet)->n     = n;
     (*packet)->type  = type;
     (*packet)->bytes = 0;
-    
+
     chk -= type;
 
     if(n == DLE)
@@ -126,6 +132,9 @@ int32 GPS_Write_Packet(int32 fd, GPS_PPacket packet)
     size_t ret;
     const char *m1, *m2;
 
+    if (gps_is_usb) 
+           return GPS_Write_Packet_usb(fd, packet);
+
     GPS_Diag("Tx Data:");
     Diag(&packet->dle, 3);    
     if((ret=GPS_Serial_Write(fd,(const void *) &packet->dle,(size_t)3)) == -1)
@@ -193,6 +202,9 @@ int32 GPS_Write_Packet(int32 fd, GPS_PPacket packet)
 int32 GPS_Send_Ack(int32 fd, GPS_PPacket *tra, GPS_PPacket *rec)
 {
     UC data[2];
+
+    if (gps_is_usb) 
+           return 1;
     
     GPS_Util_Put_Short(data,(US)(*rec)->type);
     GPS_Make_Packet(tra,LINK_ID[0].Pid_Ack_Byte,data,2);
index b552ecf017d6c3eaa18880fb496c4a6479f64ac8..31345fe3aee4941a55d771ff96230dc76418e1fe 100644 (file)
@@ -83,6 +83,14 @@ int32 GPS_Serial_On(const char *port, int32 *fd)
        DCB tio;
        COMMTIMEOUTS timeout;
 
+       if (gps_is_usb) {
+           switch (gusb_open(port)) {
+                   case 0: return NULL;
+                   case 1: return 1;
+                   case 2: exit(0);
+           }
+       }
+
        comport = CreateFile(port, GENERIC_READ|GENERIC_WRITE, 0, NULL,
                                          OPEN_EXISTING, 0, NULL);
 
@@ -143,7 +151,11 @@ int32 GPS_Serial_On(const char *port, int32 *fd)
 
 int32 GPS_Serial_Off(const char *port, int32 fd)
 {
-       CloseHandle(comport);
+       if (gps_is_usb) {
+               gusb_close(port);
+       } else {
+               CloseHandle(comport);
+       }
        return 1;
 }
 
@@ -356,7 +368,7 @@ int32 GPS_Serial_Read(int32 handle, void *ibuf, int size)
 
 int32 GPS_Serial_Write(int32 handle, const void *obuf, int size)
 {
-               return write(handle, obuf, size);
+       return write(handle, obuf, size);
 }
 
 
@@ -460,6 +472,8 @@ int32 GPS_Serial_Wait(int32 fd)
     fd_set rec;
     struct timeval t;
 
+    if (gps_is_usb) return 1;
+
     FD_ZERO(&rec);
     FD_SET(fd,&rec);
 
@@ -487,7 +501,9 @@ int32 GPS_Serial_Wait(int32 fd)
 
 int32 GPS_Serial_On(const char *port, int32 *fd)
 {
-
+    if (gps_is_usb) {
+           return gusb_init();
+    }
     if(!GPS_Serial_Savetty(port))
     {
        GPS_Error("Cannot access serial port");